package com.hellohoper.test.mybatis;

import com.hellohoper.assembly.common.utils.base.model.PageModel;
import com.hellohoper.cloud.starter.swagger.annotation.EnableSwaggerApi;
import com.hellohoper.test.mybatis.mapper.model.CityDistance;
import com.hellohoper.test.mybatis.service.CityDistanceService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * Created by hk on 12/13/16.
 */
@SpringBootApplication
@Controller
@EnableSwaggerApi
@EnableTransactionManagement
@MapperScan("com.hellohoper.test.mybatis.mapper")
public class Application {

    @Autowired
    private CityDistanceService cityDistanceService;

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @RequestMapping(value = "/api/save", method = RequestMethod.GET)
    @ResponseBody
    public int save(String distance, String depCity, String arrCity) {
        CityDistance cityDistance = new CityDistance();
        cityDistance.setCreateTime(new Date());
        cityDistance.setDistance(distance);
        cityDistance.setDepCityCode(depCity);
        cityDistance.setDepCityName(depCity);
        cityDistance.setArrCityName(arrCity);
        cityDistance.setArrCityCode(arrCity);
        cityDistance.setUpdateTime(new Date());
        cityDistance.setIsDel(false);
        int i = cityDistanceService.insertSelective(cityDistance);
        return i;
    }

    @RequestMapping(value = "/api/list", method = RequestMethod.GET)
    @ResponseBody
    public PageModel getData(int pageNum, int pageSize) throws InterruptedException {
        PageModel pageModel = cityDistanceService.selectPageList(pageNum, pageSize, null);
//        Thread.sleep(10000);
        return pageModel;
    }


}
